﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Abp.Auditing;
using Abp.Web.Models;
using FwProject.Com;
using FwProject.Com.Dto;
using FwProject.Configuration;
using FwProject.Controllers;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;

namespace FwProject.Web.Shop.Controllers
{
    public class FeedbackController : FwProjectControllerBase
    {
        private readonly IFeedbackAppService _feedbackAppService;
        private readonly IHostingEnvironment _env;

        private readonly IConfigurationRoot _appConfiguration;
        public FeedbackController(IFeedbackAppService feedbackAppService, IHostingEnvironment env)
        {
            _feedbackAppService = feedbackAppService;
            _env = env;
            _appConfiguration = _env.GetAppConfiguration();
        }
        public IActionResult Index()
        {
            return View();
        }

        [HttpGet]
        [DisableAuditing]
        [WrapResult(false, false)]//关闭ABP的返回数据封装
        public async Task<IActionResult> GetFeedbackData(int page, int limit, FeedbackFilter filter=null)
        {
            var data = await _feedbackAppService.GetFeedbackLayerDataAsync(page, limit, filter);
            return Json(data);
        }

        public async Task<IActionResult> Details(Guid id)
        {
            ViewBag.ImageUrl = _appConfiguration["ImageUrl:url"].ToString();
            var entity = await _feedbackAppService.GetEntityAsync(id);
            return View(entity);
        }

        public async Task<IActionResult> Delete(Guid id)
        {
            await _feedbackAppService.DeleteAsync(id);
            return Json(id);
        }
    }
}